package testOne2Ten;

/**
 * 输入一个整数，输出该数二进制表示中1的个数
 * 1、循环位于比较
 * 2、不知道怎么说
 * Created by Wongy on 2018/3/13.
 */
public class test10 {
    private int solution1(int num) {
        int target = 1;
        int count = 0;
        while (target != 0) {
            if ((target & num) != 0) {
                count++;
            }
            target = target << 1;
        }
        return count;
    }

    private int solution2(int num) {
        int count = 0;
        while (num > 0) {
            count++;
            num = num & (num - 1);
        }
        return count;
    }
}
